# Visualization Toolkit (VTK) Tcl package configuration.

package ifneeded vtkinit {@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@} {
  namespace eval ::vtk::init {
    proc load_library_package {libName libPath {libPrefix {@VTK_TCL_LIBNAME_PREFIX@}}} {
      #first try to load a static package, then try the shared package.
      if {[catch "load {} $libName"]} {
        set libExt [info sharedlibextension]
        set currentDirectory [pwd]
        set libFile [file join $libPath "$libPrefix$libName-@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@$libExt"]
        if {[catch "cd {$libPath}; load {$libFile}" errorMessage]} {
          puts $errorMessage
        }
        cd $currentDirectory
      }
    }
    proc require_package {name {version {@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@}}} {
      if {[catch "package require -exact $name $version" errorMessage]} {
        puts $errorMessage
        return 0
      } else {
        return 1
      }
    }
    set version {@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@}
    set kits {}
    foreach kit { base @VTK_TCL_WRAPPED_MODULES@ } {
      lappend kits [string tolower "${kit}"]
    }
  }
  package provide vtkinit {@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@}
}

foreach kit { @VTK_TCL_WRAPPED_MODULES@ } {
  package ifneeded "vtk${kit}TCL" {@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@} "
    package require -exact vtkinit {@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@}
    ::vtk::init::load_library_package {vtk${kit}TCL} {@VTK_TCL_LIBRARY_DIR@}
  "
  package ifneeded "vtk[string tolower ${kit}]" {@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@} "
    package require -exact vtkinit {@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@}
    if {\[catch {source \[file join {@VTK_TCL_SCRIPT_DIR@} {vtk[string tolower ${kit}]} {vtk[string tolower ${kit}].tcl}\]} errorMessage\]} {
      puts \$errorMessage
    }
  "
}

foreach src {vtk vtkbase vtkinteraction vtktesting} {
  package ifneeded ${src} {@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@} "
    package require -exact vtkinit {@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@}
    if {\[catch {source \[file join {@VTK_TCL_SCRIPT_DIR@} {$src} {$src.tcl}\]} errorMessage\]} {
      puts \$errorMessage
    }
  "
}
